package com.example.petplanet.result;

import jakarta.servlet.http.HttpServletResponse;
import lombok.Data;

@Data
public class Result<T> {

    private T data;
    private Integer code;
    private String msg;
    public Result() {
    }

    public Result(Integer code){
        this.code=code;
    }
    public Result(Integer code, String msg ) {
        this.code = code;
        this.msg = msg;
    }
    public Result(T data, Integer code) {
        this.code = code;
        this.data=data;
    }
    public Result(T data, Integer code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public static Result<Object> success() {
        return new Result<>(HttpServletResponse.SC_CREATED);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(data,HttpServletResponse.SC_CREATED);
    }

    public static <T> Result<T> success(T data,String msg) {return new Result<>(data,HttpServletResponse.SC_CREATED,msg);}

    public static Result<Object> error() {
        return new Result<>(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

    public static Result<Object> error(Integer code) {
        return new Result<>(code);
    }

    public static Result<Object> error(String message) {return new Result<>(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);}

    public static Result<Object> error(Integer code,String message) {return new Result<>(code, message);}

}
